import request from '../request';

interface ICreateNew {
  title: string;
  imgUrl: string;
  type: string;
  description: string;
  author: string;
  content: string;
}

/** 创建新闻 */
export const createNew = (params: ICreateNew) => request.post('/news/create', params);

interface IUpdateNew extends ICreateNew {
  uuid: string;
}

/** 更新新闻 */
export const updateNew = (params: IUpdateNew) => {
  const { uuid, ...otherParams } = params;
  return request.post(`/news/update/${uuid}`, otherParams);
}

interface IDeleteNew {
  uuid: string;
}

/** 删除新闻 */
export const deleteNew = (params: IDeleteNew) => {
  const { uuid, ...otherParams } = params;
  return request.post(`/news/remove/${uuid}`, otherParams);
}

/** 获取一条新闻 */
export const getNewByUuid = (uuid: string) => {
  return request.get(`/news/detail/${uuid}`);
}